%%


% trapz
t = 0:1/fs:(offset-onset)/fs;

%% 
out = min_jerk([filt_hand_x(onset) filt_hand_y(onset)], [filt_hand_x(offset) filt_hand_y(offset)], t);
bell_x = diff(out(:,1))*fs;
bell_y = diff(out(:,2))*fs;
bell_xy = sqrt((bell_x.^2+bell_y.^2));
bell_peak = max(bell_xy);

bell_distance = trapz(t(2:end),bell_xy);

[max_v,position] = max(bell_xy);
onset_velxy = bell_xy(1:position);
%onset
IniNum = find(onset_velxy < 0.10 * max_v);
onset_bell = IniNum(end);
%offset
offset_velxy = bell_xy(position:length(bell_xy));
LastNum = find(offset_velxy < 0.10 * max_v);
offset_bell = LastNum(1) + position -1;

%resample
increment = (offset-onset) /(offset_bell - onset_bell);
bell_shape = resample(bell_xy(onset_bell:offset_bell),floor(increment*fs),fs);
new_peak = max(bell_shape);
figure(1)
hold on,
plot(bell_shape(1:end-1),'LineWidth',4,'color','r');
plot(velxy(onset:offset),'LineWidth',4,'color','g');
